package com.homedo.microservice.open.service.gateway.persistence.dao;

import com.homedo.common.dao.BaseDao;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.bean.enums.forroutedomain.StatusEnum4RouteDomain;
import com.homedo.microservice.open.service.gateway.bean.po.RouteDomain;
import com.homedo.microservice.open.service.gateway.persistence.mapper.IRouteDomainMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 作者 jgshun
 * @date 创建时间 2018年09月18日 11时30分20秒
 */
@Repository
public class RouteDomainDao extends BaseDao<RouteDomain> {
    @Autowired
    private IRouteDomainMapper routeDomainMapper;

    public List<RouteDomain> getListByApplication(String applicationName, List<StatusEnum4RouteDomain> statuses) {
        Example example = new Example(RouteDomain.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(RouteDomain.FIELD_APPLICATIONNAME, applicationName);
        if (Detect.notEmpty(statuses)) {
            criteria.andIn(RouteDomain.FIELD_STATUS, statuses.stream().map(StatusEnum4RouteDomain::getCode).collect(Collectors.toList()));
        }

        return super.getListByExample(example);
    }
}
